<template>
	<view class="suggestion-container">

		<view class="text-box">
			<textarea :focus='sss' placeholder="请填写您的描述,以便我们提高更好的帮助和服务" class="textarea" v-model="suggestions" />
		</view>
		<view class="submit-view">
			<view class="submitBtn" @click="submit"> 提交</view>
		</view>

	</view>
</template>

<script>
	export default {
		data() {
			return {
				suggestions: ""
			}
		},
		methods: {

			submit() {
				const db = wx.cloud.database();
				const _ = wx.cloud.database().command;
				if (this.suggestions.trim() === '') {
					wx.showToast({
						title: '您还没有填写内容，填写后才能提交哦',
						icon: 'none',
						duration: 1000
					})
					return;
				}
				let time = this.formatTimeStamp((new Date()));
				let suggestion = this.suggestions.trim();
				db.collection("suggestion").add({
					data: {
						time,
						suggestion
					}
				}).then(res => {
					this.suggestions = "";
					uni.navigateTo({
						url: "../../../subpkg/suggestionSuccess/suggestionSuccess"
					})
					console.log(res)
				})

			},
			formatTimeStamp(date) {
				let year = date.getFullYear();
				let month = date.getMonth() + 1 >= 10 ? date.getMonth() + 1 : "0" + (date.getMonth() + 1);
				let day = date.getDate() >= 10 ? date.getDate() : "0" + date.getDate();
				let hour = date.getHours() >= 10 ? date.getHours() : "0" + date.getHours();
				let min = date.getMinutes() >= 10 ? date.getMinutes() : "0" + date.getMinutes();
				let second = date.getSeconds() >= 10 ? date.getSeconds() : "0" + date.getSeconds();
				return year + "-" + month + "-" + day + " " + hour + ":" + min + ":" + second;
			}
		}
	}
</script>

<style>
	.submitBtn {
		/* margin: 0 0 32upx 578upx; */
		background-color: #1296db;
		height: 56upx;
		width: 80%;
		color: #fff;
		font-size: 28upx;
		text-align: center;
		line-height: 56upx;
		border-radius: 12upx;
	}

	.submit-view {
		width: 100%;
		height: 58px;
		justify-content: center;
		display: flex;
		align-items: center;
	}

	.text-box {
		margin-left: 40upx;
		width: 670upx;
		height: 492upx;
		background: #fff;
		border-radius: 12upx;
		padding: 28upx 24upx;
	}

	.textarea {

		width: 100%;
		height: 100%;
		caret-color: #979797;
		color: #323232;
		font-size: 28upx;

	}
</style>